<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
	<HEAD>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta name="author" content="zhaozhenguo">
		<title>礼品退货申请单</title>
		<!--js库及样式-->
		<script language="javascript" src="../script/common.js" type="text/javascript"></script>
		<!--动态js-->
		<script language="javascript" type="text/javascript">
			//全局变量
			var org = Common.cOrg();	//当前单位
			var operatorName=Common.cOperator().name;
			var qt = {};
			var qtmx = {};				//数据表格对象
			var orderid;
			var giftid;
			var likeid;
			var b;//GiftOrder   
	
			//页面加载方法
			function load(){
				Eui.showNavigation();
				setPages(["listview","selectdetview","detview","detviewmx","detviewmxxz","neworder","printview"]);	
				createTable();	
			}
			function createTable(){
				var columns =[];
				columns[0]={type:"checkbox"}
				columns[6]={title:"操作",width:"15%",render:czFunc,order:false}
				/*var columns = [	
					{type:"checkbox"},		//复选框
					{title:"礼品退货申请单号",width:"20%"},	
					{title:"操作员姓名",width:"15%"},                        //点击进入修改		
					{title:"申请日期",width:"15%",render:function(v){return v?v.format():""}},			
					{title:"最近修改间",width:"15%",render:function(v){return v?v.format():""}},
					{title:"交货时间",width:"20%",render:function(v){return v?v.format():""}},	
					{title:"操作",width:"15%",render:czFunc,order:false}
				]*/
				qt = new QueryTable("loy_gift_backstr_query_bill","searchForm","datalist",columns,{
					buttons:[
						{value:"增 加",actions:onNew},
						{value:"删 除",actions:onDelete1}
					]
				});
			}
			function mxcreateTable(){
				var columns =[];
				columns[0]={type:"checkbox"}
				columns[7]={title:"操作",width:"15%",render:czmxFunc,order:false}
				/*var columns = [
					{type:"checkbox"},		//复选框
					{title:"商品大类型",width:"15%"},	
					{title:"商品子类型",width:"15%"},	                      //点击进入修改
					{title:"商品名称",width:"15%"},						
					{title:"退货申请数量",width:"14%"},					
					{title:"计量单位",width:"10%"},
					{title:"备注",width:"16%"},
					{title:"操作",width:"15%",render:czmxFunc,order:false}
				]*/
				qtmx = new QueryTable("loy_gift_backstr_query_item","","mxdatalist",columns,{showData:"true",
					buttons:[
						{value:"增 加",actions:xzFunc},
						{value:"删 除",actions:onDelete},
						{value:"返 回",actions:resetFunc}
					]
				});
				qtmx.paramFunc = function(){
					var params = {};
					params.giftOrder = likeid;
					return params;
				}
			}
		    function back(){
				createTable();
				showData();
				switchPage('listview');			
			}
			function showData(){
			 $("reqDateTime1").value=formatEndDay($("reqDateTime").value);
			 $("reqDeliDate1").value=formatEndDay($("reqDeliDate").value);
				qt.showTable();
			}
			function formatEndDay(str)
			{
			  if(str != "" && str != null){
		      var d = str.split("-");
		      d = new Date(new Number(d[0]),(new Number(d[1]) -1),new Number(d[2]) + 1);
		      d = new Date(d-1000);
		      return d.format("yyyy-MM-dd hh:mm:ss");
	            }
	            return "";	
			}
			function czmxFunc(v,r){
				return "<a href=# onclick=\"xiugai("+r[0]+",'"+r[3]+"','"+r[4]+"','"+r[5]+"','"+r[6]+"');return false;\">修改</a>"
			}
			function czFunc(v,r){
				return "<a href=# onclick=\"create("+r[0]+",'"+r[1]+"','"+r[2]+"','"+r[3]+"','"+r[4]+"');return false;\">操作</a>"
			}
			function xiugai(id,giftName,reqQty,baseUOM,comments){
		      	if (id != null){
			      	$("caigoumx").id.value=id;
			      	$("giftName").innerHTML=giftName;
			      	$("caigoumx").reqQty.value=reqQty;
			      	$("baseUOM").innerHTML=baseUOM;
			      	if(comments=="null"){
			      		comments="";
			      	}
			      	$("caigoumx").comments.value=comments;
					switchPage("detviewmx");
				}
			}
			function create(id,codeid,opera,update,over){
			    likeid=id;
			    var date = new Date(update)
			    var date2 = new Date(over)
				if (id != null){
				 	$("caigouid").innerHTML=codeid;
				 	$("updatetime").innerHTML=update;
				 	$("oper").innerHTML=opera;
				 	
		                $("zdtime").innerHTML=over;
		        
					switchPage("selectdetview");
			 		mxcreateTable();	
				}
			}					     
			function onUpdateOrder(){
				if(!checkForm("inventoryorder"))return;
				var date1=$("inventoryorder").reqDeliDate2.value;
				DWR.call('giftStorageService.updateGiftOrder',orderid,date1,function(v){
					$("zdtime").innerHTML=v.reqDeliDate.format();
					switchPage("detview");
				});
			}
			//显示新增界面
			var b;
			function onNew(){	
				DWR.call('giftStorageService.createGiftOrder',2,function(v){
					getOrderId(v.id);
					$("caigouid2").innerHTML=v.orderCode;
					$("zdtime2").innerHTML=v.reqDateTime.format();
					$("oper2").innerHTML=operatorName;
					orderid=v.id;
					switchPage("neworder");
				});
			}
			function getOrderId(d){
			     b=d;
			}
			//选择单位控件
			function selOrg(){			
				var v = openDialogFrame("/client/loy_giftinventory_list.html",'选择商品',500,600)
				if (v){		
	            	white_enterform.awardname.value = v.name;
				    giftid=v.id;
				}
			}
			function selOrg2(){			
				var v = openDialogFrame("/client/loy_giftinventory_list.html",'选择商品',500,600)
				if (v){		
	            	$("caigoumxxz").giftName.value = v.name;
				    giftid=v.id;
				}
			}
			//取消方法
			function resetFunc(){
			   switchPage('listview');
			   showData();
			}
			
			function refunc(){
				showData();
				switchPage('listview');
			}
			//保存方法
			function onSave(){
			   	if(!checkForm(white_enterform))return;
		    	var white_enter = Common.getValues(white_enterform);
			    if (!white_enter.id)
			    	white_enter.giftOrder=b;
			    	white_enter.gift=giftid;
				DWR.call('giftStorageService.addGiftItem',white_enter,2,function(v){
		        	if(v==1){
		         		showInformation("添加失败，已有此商品了");
		          	}
		          	else if(v==2){
		          		showError("库存不够");
		         	}
		          	else{
		           		showInformation("添加成功!");
		          	}
		    	});
			    white_enterform.reset();			  
			}
			function onSaveBill(){
			  	DWR.call('giftStorageService.saveBackBill',likeid,function(v){  
			  	giftId =v.id;
			  	requestframe.document.location.href = "print_backstr_gift.html";
			  	switchPage("printview"); 
			});
			}   
			function mxxzonSavexg(){
			   	if(!checkForm("caigoumxxz"))return;
				var giftItem = Common.getValues("caigoumxxz");
				if (!giftItem.id)
				giftItem.giftOrder=likeid;
				giftItem.gift=giftid;
				DWR.call('giftStorageService.addGiftItem',giftItem,2,function(v){
					if(v==1){
						showError("添加失败，已有此商品了");
					}
					else if(v==2){
						showError("库存不够");
					}
					else{
						showInformation("添加成功!");
					}
				});
				white_enterform.reset();
			}
			function onSavexg(){
			    if(!checkForm("caigoumx"))return;
			    var giftItem=Common.getValues("caigoumx");
				DWR.call('giftStorageService.updateGiftItem',giftItem,2,function(v){
				    if(v==2){
				   		showError("库存不够");
				    }else{
				    	showInformation("修改成功!");
				    } 
				    switchPage('selectdetview');
					mxcreateTable();	
			    });
			}	
			function qx(){
				switchPage('selectdetview');
				mxcreateTable();
			}
			function xzFunc(){
				$("caigoumxxz").reset();
				switchPage('detviewmxxz');
			}
			function resetItem(){
		    	white_enterform.reset();
			}
			function resetItem2(){
		    	$("caigoumxxz").reset();
			}
			function mxshowData(){
			qtmx.showTable();
			}
			//删除方法
			function onDelete(){
				var	id = qtmx.getBoxValue();
				if(id==null||id==""){
					showWarning("请选择您确定要删除的数据");return;
				}
				if(showQuestion("确定删除吗?")==false){
					return;
				}
				var ids = id.split(",");
				DWR.call('giftStorageService.deleteGiftItemByIds',ids,function(v){
				
		           	mxshowData(); 
		          	showInformation("删除成功!");
			    });
				switchPage('selectdetview');
			}
			function onDelete1(){
				var	id = qt.getBoxValue();
				if(id==null||id==""){
					showWarning("请选择您确定要删除的数据");return;
				}
				if(showQuestion("确定删除吗?")==false){
					return;
				}
				var ids = id.split(",");		
				DWR.call('giftStorageService.deleteGiftOrderByIds',ids,function(v){
		           	showData();
		           	showInformation("删除成功!");
			    });
				switchPage('listview');
			}
			function blakItemList(){
				DWR.call('giftStorageService.getOrder',b,function(v){
				    $("caigouid").innerHTML=v.orderCode;
				 	$("updatetime").innerHTML=v.reqDateTime.format();
				 	$("oper").innerHTML=v.operator;        
			    });
			    likeid=b;
				switchPage("selectdetview");
			    mxcreateTable();   	    
			}
			function onCanc(){
				switchPage('listview');
			}
		</script>
	</HEAD>
	<body onload="load()">
		<!--页面导航-->
		<div class="nav"><div id="nav">&nbsp;</div></div>
		<!--查询静态页面部分-->
		<div id="listview" style="">	
			<div class="searchForm">
				<form id="searchForm" name="searchForm">
					<table cellSpacing="0" cellPadding="4" width="100%" border="0" >
						<tr>  
					    	<td><label>退货申请单号</label> 
					    	<input type="text" name="orderCode" maxlength="15"></td>
					        <td><label>操&nbsp;&nbsp;作&nbsp;&nbsp;员&nbsp;&nbsp;</label> <input type="text" name="operator" maxlength="40"></td>
						</tr>
						<tr>
						    <td><label>退货申请日期</label> 
						    <input type="text" name="reqDateTime" onBlur="checkV(this,'_pastDate')"><a href="#" onclick="showDatePicker($('reqDateTime'));" class="date" title="选择日期">&nbsp;&nbsp;</a></td>
						    <td><label>申请交货日期</label> 
						   <input type="text" name="reqDeliDate" onBlur="checkV(this,'_futureDate')"><a href="#" onclick="showDatePicker(searchForm.reqDeliDate);" class="date" title="选择日期">&nbsp;&nbsp;</a></td>
						   <td><button type="button" onclick="showData()">查 询</button></td>
						   <td> <input type="hidden"  name="reqDateTime1" id="reqDateTime1 " /> </td>
						   <td> <input type="hidden"  name="reqDeliDate1" id="reqDeliDate1 " /> </td>
						</tr>
					</table>
				</form>	
			</div>
			<div id="datalist"></div>	
		</div>
		<div id="selectdetview" style="display: none;">
			<div class="form">
				<form id="s_card_outform" name="s_card_outform">
					<input type="hidden" name="id"> <input type="hidden" name="organization">
					<div class="formTitle">商品信息列表</div>
					<table cellSpacing=0 cellPadding=4 width="100%" border=0 class="viewTable">
						<tr>
							<td><label>退货申请单号</label> <span id="caigouid"></span></td>
							<td><label>操&nbsp;&nbsp;作&nbsp;&nbsp;员</label> <span id="oper"></span></td>
						</tr>
						<tr>
							<td><label>退货申请时间</label> <span id="updatetime"></span></td>
		           			<td><label>申请交货时间</label> <span id="zdtime"></span></td>
						</tr>
					</table>
					<input type=hidden name="count" id="count" value="" onblur="checkV(this,'',true)">
				</form>
			</div>	
			<div id="mxdatalist"></div>
			<div align="center"><button type="button" onclick="onSaveBill()">保存</button></div>
		</div>
		<div class="printview" id="printview" style='display:none;'>
			<iframe id="requestframe" name="requestframe" style="width:100%;height:90%;overflow:auto;" frameborder=0 src=""></iframe>
		</div>
	<!--明细(新增)静态页面部分-->
		<div id="detview" style="display:none;">
			<div class="form">
				<form id="white_enterform" name="white_enterform">
					<input type="hidden" name="giftOrder">
					<input type="hidden" name="gift">
					<div class="formTitle">商品详细信息</div>
					<table cellSpacing=0 cellPadding=4 width="100%" border=0>
						<tr>
							<td><label>商品名称</label> <input type="text" name="awardname" onblur="checkV(this,'',true)" readonly class="readonly"><a class=orga href=# onclick="selOrg()" return false;><font class="des">*</font></td> 
							<td><label>退货申请数量</label> <input type="text" name="reqQty" onblur="checkV(this,'number',true)" maxlength=8><font class="des">*</font></td>
						</tr>
						<tr>		
							<td><label>备&nbsp;&nbsp;&nbsp;&nbsp;注</label> <input type="text" name="comments"  maxlength="32"></td>
						</tr>		
					</table>
					<div  align="center">
						<button type=button onclick="onSave()">添 加</button> 
						<button type=button onclick="resetItem()">清 除</button> 
						<button type=button onclick="onCanc()">取 消</button> 
						<button type=button onclick="blakItemList()">返 回</button>
					</div>
				</form>
			</div>
		</div>
		<div id="detviewmx" style="display:none;">
			<div class="form">
				<form id="caigoumx" name="caigoumx">
					<input type="hidden" name="id">
					<div class="formTitle">修改礼品退货申请项</div>
					<table cellSpacing=0 cellPadding=4 width="100%" border=0>
						<tr>
							<td><label>商品名称</label> <span id="giftName"></span></td>
							<td><label>退货申请数量</label> <input type="text" name="reqQty" onblur="checkV(this,'number',true)"  maxlength=15><font class="des">*</font></td>
						</tr>
						<tr>		
							<td><label>计量单位</label> <span id="baseUOM"></span></td>
							<td><label>备&nbsp;&nbsp;注&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label> <input type="text" name="comments"  maxlength="32"></td>
						</tr>			
					</table>
					<div align="center">
						<button type=button onclick="onSavexg()">修 改</button> 
						<button type=button onclick="qx()">取 消</button>
					</div>
				</form>
			</div>
		</div>
		<div id="detviewmxxz" style="display:none;">
			<div class="form">	
				<form id="caigoumxxz" name="caigoumxxz">
					<input type=hidden name="id">
					<div class="formTitle">添加礼品退货申请项</div>
					<table cellSpacing=0 cellPadding=4 width="100%" border=0>
						<tr>
							<td><label>商品名称</label> <input type="text" name="giftName" onblur="checkV(this,'',true)" readonly class="readonly"><a class="orga" href=# onclick="selOrg2()" return false;><font class="des">*</font></td>  
							<td><label>退货申请数量</label> <input type="text" name="reqQty" onblur="checkV(this,'number',true)" maxlength=15><font class="des">*</font></td>
						</tr>
						<tr>		
							<td><label>备&nbsp;&nbsp;注&nbsp;&nbsp;</label> <input type="text" name="comments"  maxlength="32"></td>
						</tr>		
					</table>
					<div align="center">
						<button type=button onclick="mxxzonSavexg()">确 定</button> 
						<button type=button onclick="resetItem2()">清 除</button> 
						<button type=button onclick="qx()">返 回</button>
					</div>
				</form>
			</div>
		</div>
		<div id="neworder" style="display:none;">
			<div class="form">
				<form id="inventoryorder" name="inventoryorder">
					<input type="hidden" name="neworderid">
					<div class="formTitle">填写礼品退货申请单据</div>
					<table cellSpacing=0 cellPadding=4 width="100%" border=0 class="viewTable">
					     <tr>
							<td><label>申请单号</label> <span id="caigouid2"></span></td>
							<td><label>操&nbsp;&nbsp;作&nbsp;&nbsp;员</label> <span id="oper2"></span></td>
						</tr>
						<tr>
							<td><label>退货申请时间</label> <span id="zdtime2"></span></td>
						    <td><label>申请交货日期</label> <input type="text" name="reqDeliDate2" onblur="checkV(this,'_futureDate',true)"><a href="javascript:void(0)" onclick='showDatePicker( $("reqDeliDate2"));' class="date" title="选择日期">&nbsp;&nbsp;</a><font class="des">*</font></td>
						</tr>	
					</table>
					<br>
					<br>
					<div align="center">
						<button type="button" onclick="onUpdateOrder()">添加礼品项</button>
						<button type="button" onclick="switchPage('listview');">取消单据</button>
					</div>
				</form>
			</div>
		</div>
	</body>
</HTML>
	